home *** CD-ROM | disk | FTP | other *** search
- /*
- File: DragPriv.cpp
-
- Contains: Implementation of Private classes for ODDragAndDrop.
-
- Owned by: Vincent Lo
-
- Copyright: © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 3/15/96 DH 1287259 - 1.0.2 Don't get back what I put
- in the scrapbook. Changed ODMemContainer so
- that it has a constructor that makes a new
- container given a container handle.
- <27> 10/13/95 EL 1287340: Use standard ISO prefix
- <26> 10/4/95 jpa Added missing ODVolatiles [1285799]
- <25> 10/4/95 VL 1287585: Check to see whether we are
- dragging a folder before getting the file
- info.
- <24> 9/13/95 VL 1283523: Stop copying names for stationery
- files.
- <23> 9/8/95 VL 1274572: Preserved the curResFile in
- GetIconFamilyFromFile.
- <22> 9/8/95 TÇ 1281096 FB2:Many constants in ODTypesB
- without kOD prefix!
- <21> 9/6/95 VL 1274572: Added GetFinderInfo and
- GetIconFamilyFromFile.
- <20> 8/12/95 TÇ 1276812 Need to use TempObjs and TempRefs
- for exception safety and to avoid TRY
- blocks, 1276807 Opt./Bug: use StdTypIO
- routines for portable streaming & smaller
- footprint
- <19> 7/26/95 VL 1270320: ClearAllPromises when deleting
- memory container.
- <18> 5/26/95 VL 1251403: Multithreading naming support.
- <17> 5/25/95 jpa Fixed usage of ODDebug. [1253321]
- <16> 4/25/95 VL 1240737: Make sure that ID for file
- container is set to the right _length.
- <15> 4/15/95 VL 1240014: turned off debug statements.
- <14> 4/14/95 VL Temporarily turned on debug printf.
- <13> 3/10/95 VL 1227218: Get rid of system heap.
- <12> 2/27/95 VL 1198037: Removed debugstr from code.
- <11> 2/10/95 VL 1205627: Used kODBentoUpdateContainer.
- <10> 1/26/95 VL #???: Use updated Storage Unit Ref API.
- <9> 1/19/95 CC 1212419 Pass kODBentoMemoryContainer to
- CreateMemoryContainer & GetMemoryContainer.
- <8> 12/20/94 VL 1195012: Make Storage calls be
- marshallable.
- <7> 12/13/94 VL 1203627,1200603,1203451,1198037,1194537,119
- 4755,1186815: Bug fixes.
- <6> 9/23/94 VL 1184272: ContainerID is now a sequence of
- octets.
- <5> 8/26/94 VL 1183174: Use updated cloning APIs
- (specifically GetStorageUnitRef takes ID
- now).
- <4> 8/15/94 TÇ #1180922 Removed most obsolete types from
- StdTypes.idl
- <3> 8/3/94 VL 1153123: Storage to ODStor.
- <2> 7/26/94 VL Got rid of dependency on Bento.
- <1> 7/21/94 VL first checked in
-
- To Do:
- In Progress:
- */
-
- #ifndef _DRAGPRIV_
- #include <DragPriv.h>
- #endif
-
- #ifndef SOM_ODStorageSystem_xh
- #include <ODStor.xh>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <ODDraft.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef _STDTYPIO_
- #include "StdTypIO.h"
- #endif
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
-
- #ifndef _ISOSTR_
- #include <ISOStr.h>
- #endif
-
- #ifndef _INFOUTIL_
- #include <InfoUtil.h>
- #endif
-
- #ifndef _ICONS_
- #include <Icons.h>
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- #ifndef __FINDER__
- #include <Finder.h>
- #endif
-
- #if ODDebug
- #ifndef __STRINGS__
- #include <Strings.h>
- #endif
- #endif
-
- #if ODDebug
- // #define ODDebug_DragPriv 1
- #endif
-
- const ODContainerType kODBentoUpdateContainer = "+//ISO 9070/ANSI::113722::US::CI LABS::OpenDoc:Bento Container Suite:ContainerType:Update";
-
- //==============================================================================
- // Function Prototype
- //==============================================================================
-
- ODContainerType GetContainerSuiteType(FSSpec* fsSpec);
-
- //==============================================================================
- // ODDragItem
- //==============================================================================
- //------------------------------------------------------------------------------
- // ODDragItem::ODDragItem
- //------------------------------------------------------------------------------
- ODDragItem::ODDragItem(ODStorageSystem *storage, ODBoolean IsForeignDataSU)
- {
- fStorageSystem = storage;
- fContainer = kODNULL;
- fDocument = kODNULL;
- fDraft = kODNULL;
- fSU = kODNULL;
- }
-
- void ODDragItem::Open(Environment* ev)
- {
- WARN("ODDragItem::Open should not be called.");
- }
-
-
- void ODDragItem::Close(Environment* ev)
- {
- WARN("ODDragItem::Open should not be called.");
- }
-
- //==============================================================================
- // ODMemDragItem
- //==============================================================================
- //------------------------------------------------------------------------------
- // ODMemDragItem::~ODMemDragItem
- //------------------------------------------------------------------------------
-
- ODMemDragItem::ODMemDragItem(ODStorageSystem *storage, ODHandle containerH, ODBoolean IsForeignDataSU)
- : ODDragItem(storage,IsForeignDataSU)
- {
- fContainerHandle = containerH;
- }
-
-
- ODMemDragItem::~ODMemDragItem()
- {
- Environment* ev = somGetGlobalEnvironment();
-
- if (fSU != kODNULL)
- {
- fSU->ClearAllPromises(ev);
- fSU->Release(ev);
- }
- if (fDraft != kODNULL)
- fDraft->Release(ev);
- if (fDocument != kODNULL)
- fDocument->Release(ev);
- if (fContainer != kODNULL)
- fContainer->Release(ev);
- ODDisposeHandle(fContainerHandle);
- }
-
- //------------------------------------------------------------------------------
- // ODMemDragItem::Initialize
- //------------------------------------------------------------------------------
- void ODMemDragItem::Initialize(Environment* ev)
- {
- ODDragItem::Initialize(ev);
-
- fContainerHandle = ODNewHandle(0);
- ASSERTM(MemError() == noErr, MemError(), "Error allocating D&D container handle");
-
- fContainer = CreateMemoryContainer(ev, fStorageSystem->GetSession(ev), fContainerHandle, kODBentoMemoryContainer);
- fDocument = fContainer->AcquireDocument(ev, kODDefaultDocument);
- fDraft = fDocument->AcquireBaseDraft(ev, kODDPExclusiveWrite);
- fSU = fDraft->CreateStorageUnit(ev);
- TempODStorageUnit draftProperties = fDraft->AcquireDraftProperties(ev);
- ODSetStrongSURefProp(ev, draftProperties, kODPropRootPartSU, kODStrongStorageUnitRef, fSU->GetID(ev));
- }
-
- //------------------------------------------------------------------------------
- // ODMemDragItem::Open
- //------------------------------------------------------------------------------
- void ODMemDragItem::Open(Environment* ev)
- {
- fContainer = GetMemoryContainer(ev, fStorageSystem->GetSession(ev), fContainerHandle, kODBentoMemoryContainer);
- fDocument = fContainer->AcquireDocument(ev, kODDefaultDocument);
- fDraft = fDocument->AcquireBaseDraft(ev, kODDPExclusiveWrite);
- TempODStorageUnit draftProperties = fDraft->AcquireDraftProperties(ev);
- fSU = fDraft->AcquireStorageUnit(ev, ODGetStrongSURefProp(ev, draftProperties, kODPropRootPartSU, kODStrongStorageUnitRef));
- }
-
- //------------------------------------------------------------------------------
- // ODMemDragItem::Close
- //------------------------------------------------------------------------------
- void ODMemDragItem::Close(Environment* ev)
- {
- if (fSU != kODNULL) {
- fSU->Release(ev);
- }
- if (fDraft != kODNULL) {
- fDraft->Externalize(ev);
- fDraft->Release(ev);
- }
- if (fDocument != kODNULL)
- fDocument->Release(ev);
- if (fContainer != kODNULL)
- fContainer->Release(ev);
- }
-
- //==============================================================================
- // ODFileDragItem
- //==============================================================================
- //------------------------------------------------------------------------------
- // ODFileDragItem::~ODFileDragItem
- //------------------------------------------------------------------------------
- ODFileDragItem::~ODFileDragItem()
- {
- #if ODDebug_DragPriv
- somPrintf("~ODFileDragItem: %x %x %x %x\n", fSU, fDraft, fDocument, fContainer);
- #endif
-
- Environment* ev = somGetGlobalEnvironment();
-
- if (fSU != kODNULL)
- fSU->Release(ev);
- if (fDraft != kODNULL)
- fDraft->Release(ev);
- if (fDocument != kODNULL)
- fDocument->Release(ev);
- if (fContainer != kODNULL)
- fContainer->Release(ev);
- }
-
- //------------------------------------------------------------------------------
- // ODFileDragItem::Initialize
- //------------------------------------------------------------------------------
- void ODFileDragItem::Initialize(Environment* ev, ODContainerID* containerID)
- {
- ODDragItem::Initialize(ev);
-
- ODStorageUnitID suid;
- ODContainerType containerType = kODNULL; ODVolatile(containerType);
-
- TRY
- containerType = GetContainerSuiteType((FSSpec*) containerID->_buffer);
- containerID->_length = sizeof(short) + sizeof(long) + ((FSSpec*) containerID->_buffer)->name[0] + 1;
- fContainer = fStorageSystem->CreateContainer(ev, containerType, containerID);
- fDocument = fContainer->AcquireDocument(ev, kODDefaultDocument);
- fDraft = fDocument->AcquireBaseDraft(ev, kODDPExclusiveWrite);
- TempODStorageUnit draftProperties = fDraft->AcquireDraftProperties(ev);
- suid = ODGetStrongSURefProp(ev, draftProperties, kODPropRootPartSU, kODStrongStorageUnitRef);
- fSU = fDraft->AcquireStorageUnit(ev, suid);
- ODDisposePtr(containerType);
- #if ODDebug_DragPriv
- somPrintf("ODFileDragItem::Initialize %x %x %x %x\n", fSU, fDraft, fDocument, fContainer);
- #endif
-
- CATCH_ALL
- #ifdef ODDebug_DragPriv
- ODError err = ErrorCode();
- WARN("Error in ODFileDragItem::Initialize");
- char errString[100];
- numtostring(err, errString);
- WARN(errString);
- #endif
- ODReleaseObject(ev,fSU);
- ODReleaseObject(ev,fDraft);
- ODReleaseObject(ev,fDocument);
- ODReleaseObject(ev,fContainer);
- ODDisposePtr(containerType);
- RERAISE;
- ENDTRY
- }
-
- //==============================================================================
- // ODDragLink
- //==============================================================================
- //------------------------------------------------------------------------------
- // ODDragLink::ODDragLink
- //------------------------------------------------------------------------------
- ODDragLink::ODDragLink(ODDragItem *theItem, ODBoolean cleanup)
- {
- fItem = theItem;
- fCleanup = cleanup;
- }
-
- //------------------------------------------------------------------------------
- // ODDragLink::~ODDragLink
- //------------------------------------------------------------------------------
- ODDragLink::~ODDragLink()
- {
- if (fCleanup)
- delete fItem;
- }
-
- //------------------------------------------------------------------------------
- // GetContainerSuiteType
- //------------------------------------------------------------------------------
-
- ODContainerType GetContainerSuiteType(FSSpec* fsSpec)
- {
- #if USE_GETCONTAINER_SUITE_TYPE
- PlatformFile file;
- file.Specify(fsSpec);
-
- ODContainerType containerType = file.AcquireContainerType();
- if (ODISOStrEqual(containerType, kODBentoFileContainer) ||
- ODISOStrEqual(containerType, "")) {
- containerType = kODBentoUpdateContainer;
- }
- #else
- ODULong len = strlen(kODBentoUpdateContainer);
- ODContainerType containerType = (ODContainerType) ODNewPtr(len + 1);
- strcpy(containerType, kODBentoUpdateContainer);
- return containerType;
- #endif
- }
-
- //------------------------------------------------------------------------------
- // GetFinderInfo
- //------------------------------------------------------------------------------
- void GetFinderInfo(Environment* ev, ODStorageUnit* su, PlatformFile* file)
- {
- if (!file->IsDirectory())
- {
- ODTime creationDate = file->GetFileCreationDate();
- ODSetCreationDate(ev, su, creationDate);
- ODTime modDate = file->GetFileModDate();
- ODSetModificationDate(ev, su, modDate);
-
- if (!file->IsStationery())
- {
- ODName* name = file->GetName();
- ODSetPONameUsingSU(ev, su, name);
- DisposeIText(name);
- }
-
- // Stationery bit is purposedly left out.
- }
- }
-
- //------------------------------------------------------------------------------
- // GetIconFamilyFromFile
- //------------------------------------------------------------------------------
- void GetIconFamilyFromFile(Environment* ev, ODStorageUnit* su, PlatformFile* file)
- {
- if (!file->IsDirectory())
- {
- Handle iconFamily;
-
- short refNum = 0;
- ODBoolean hasCustomIcon;
- OSErr err = noErr;
- ODVolatile(err);
- TRY
- hasCustomIcon = file->HasCustomIcon();
- if (hasCustomIcon)
- {
- file->SetPermission(fsRdPerm);
- refNum = CurResFile();
- file->OpenResFile();
- }
- CATCH_ALL
- UseResFile(refNum);
- ENDTRY
-
- if (hasCustomIcon && (err == noErr))
- {
- err = GetIconSuite(&iconFamily, kCustomIconResource, svAllAvailableData);
- if (err == noErr)
- {
- ODSetIconFamilyProp(ev, su, kODPropCustomIcon, kODIconFamily, iconFamily, kODFalse);
- DisposeIconSuite(iconFamily, true);
- }
- #ifdef ODDEBUG
- else
- WARN("Problem getting icon family: %d ", err);
- #endif
- file->CloseResFile();
- }
- }
- }
-
-